
# automatic compilation of C++ source files of the project
# this source file was modified, so it is a good time to check if it 
# has new header files dependencies                                  

$(dir_obj)/%.o : $(dir_src)/%.$(source_extension)
	$(show) ""                                                            ; \
	echo  "---------------------------------------- "                     ; \
	echo  "Compiling $<"                                                  ; \
	$(cxx) $(final_prj_inc_dir) $(compile_flags) $(final_prj_minus_d) $< -o $@ ;




# 	$(make_cmd) dependencies class=code src_file=$< to_parse_file=$<        \
#	                          obj_dir="$(dir_obj)"                        ; \



# automatic compilation of C source files of the project
$(dir_obj)/%.o : $(dir_src)/%.c
	$(show) ""                                                            ; \
	echo  "---------------------------------------- "                     ; \
	echo  "Compiling $<"                                                  ; \
	$(cxx) $(final_prj_inc_dir) $(compile_flags) $(final_prj_minus_d) $< -o $@ ;


# automatic generation of header code files from qt-designer '.$(qt_extension)' files
$(dir_inc)/%.$(header_extension): $(dir_inc)/%.$(qt_extension)
	$(show) ""                                                            ; \
	echo  "---------------------------------------- "                     ; \
	echo  "Generating $@ from  $<"                                        ; \
	uic  -o $@ $<                                                         ;

# automatic generation of source code files from qt-designer '.ui' files
#$(dir_src)/%.$(source_extension): $(dir_src)/%.$(qt_extension)
#	$(show) ""                                                            ; \
#	echo  " ---------------------------------------- "                    ; \
#	echo  "Generating $@ from  $<"                                        ; \
#	uic -o $@ -impl $(dir_code)/$*.$(header_extension) $<                 ;

code_compile_ui: $(qt_code_hs) 
#$(qt_code_cpps) 

# **************  builds the code for a program
code_build_pgm : code_build_header
	$(show) ""                                                           ; \
	echo "Building a program for $(project)"                             ; \
	$(program_command) $(program_prefix)$(project)$(program_sufix)         \
		$(code_objs) $(final_prj_static_libs)                          \
		$(final_prj_lib_dir) $(final_prj_shared_libs)                  \
		$(search_lib_dir)                                            ; \
	mv $(program_prefix)$(project)$(program_sufix) $(dir_bin)            ; 


# soname creation - not used



# **************  builds the code for a static and shared library
code_build_lib : code_build_header
	$(show) ""                                                           ; \
	echo "Building a static lib for $(project)"                          ; \
	mkdir $(build_lib_dir) 2> /dev/null                                  ; \
	$(static_command) $(static_prefix)$(project)$(static_sufix)            \
                $(code_objs) $(final_prj_static_libs) 2> /dev/null           ; \
	mv $(static_prefix)$(project)$(static_sufix) $(dir_lib)              ; \
	echo "Building a shared lib for $(project)"                          ; \
	$(shared_command)                                                      \
		$(shared_prefix)$(project)$(shared_sufix).$(M_version).$(m_version).$(build_number) \
                $(code_objs) $(final_prj_static_libs)                          \
                $(final_prj_lib_dir) $(final_prj_shared_libs)                  \
		$(shared_soname)$(shared_prefix)$(project)$(shared_sufix)      \
		$(search_lib_dir)                                            ; \
	mv $(shared_prefix)$(project)$(shared_sufix)* $(dir_lib)             ; \
	ldconfig -n $(dir_lib) 2> /dev/null                                  ; 


# **************  builds the code for just copying files
code_build_just_copy : code_build_header


# **************  installs the header files for the code
code_build_header :
	$(show) ""                                                           ; \
	if [ ! -d $(dir_inc) ]; then                                           \
		mkdir -p $(dir_inc) 2> /dev/null                             ; \
		touch $(dir_inc)/dummy.h 2> /dev/null                        ; \
	fi                                                                   ;




#                            PUBLIC 

#@public@|code_compile|Compiles the Code of the Project
#@public_detailed@|code_compile|Syntax: 'make project=<project-name> [coc=<cpu-os-compiler>] [verbose=0/1]  [target=debug/release] code_compile
#@public_detailed@|code_compile|Where <project-name> is an existing project. Please rum 'make prj_list' to list all the avaiable projects.
#@public_detailed@|code_compile|Where <cpu-os-compiler> is the name of a file that contain definitions for a CPU, OS and compiler. Please, run 'make coc_list' to list all the combinations avaiables.
code_compile :  code_compile_ui $(code_objs)




#@public@|code_compile_chain|Compiles the code of all the projects that this project depends on, and the project itself.
#@public_detailed@|code_compile_chain|Syntax: 'make project=<project-name> [coc=<cpu-os-compiler>] [verbose=0/1]  [target=debug/release] code_compile_chain
#@public_detailed@|code_compile_chain|Where <project-name> is an existing project. Please rum 'make prj_list' to list all the avaiable projects.
#@public_detailed@|code_compile_chain|Where <cpu-os-compiler> is the name of a file that contain definitions for a CPU, OS and compiler. Please, run 'make coc_list' to list all the combinations avaiables.

code_compile_chain :
	$(show) ""                                                           ; \
	echo "**************************************** "                     ; \
	echo -n "Compiles the code of all Projects that $(project) "         ; \
	echo "depend on"                                                     ; \
	$(make_cmd) chain chain_target=code_compile                          ; \
	$(make_cmd) code_compile                                             ;


#@public@|code_build|Builds the Code of the Project
#@public_detailed@|code_build|Syntax: 'make project=<project-name> [coc=<cpu-os-compiler>] [verbose=0/1]  [target=debug/release] code_build
#@public_detailed@|code_build|Where <project-name> is an existing project. Please rum 'make prj_list' to list all the avaiable projects.
#@public_detailed@|code_build|Where <cpu-os-compiler> is the name of a file that contain definitions for a CPU, OS and compiler. Please, run 'make coc_list' to list all the combinations avaiables.
#@public_detailed@|code_build|If the Project builds a program, i.e. the variable 'product_type' in the 'tenacitas.build_system/cpp/bin/$(project)/tool/gmake/project.mk' file values '$(program)', the executable generated is placed in the directory referenced in the variable 'build_bin_dir', which is defined in the 'tenacitas.build_system/cpp/tool/gmake/cpu_os_comp/$(coc).mk' file. 
#@public_detailed@|code_build|If the Project builds a libray, i.e. the variable 'product_type' in the 'tenacitas.build_system/cpp/bin/$(project)/tool/gmake/project.mk' file values '$(library)', the static and dymanic libraries generated are placed in the directory referenced in the variable 'build_lib_dir', which is defined in the 'tenacitas.build_system/cpp/tool/gmake/cpu_os_comp/$(coc).mk' file. 
#@public_detailed@|code_build|If the variable 'product_type' in the 'tenacitas.build_system/cpp/bin/$(project)/tool/gmake/project.mk' file values '$(just_copy_files)', the existing files in the directory 'tenacitas.build_system/cpp/src/$(project)/code' are copied to the directory referenced in the variable 'build_inc_dir', which is defined in the 'tenacitas.build_system/cpp/tool/gmake/cpu_os_comp/$(coc).mk' file.
code_build: setup code_compile
	$(show) ""                                                           ; \
	echo "**************************************** "                     ; \
	echo "Building code for $(project)"                                  ; \
	if [ $(product_type) = "pgm" ]; then                                   \
		$(make_cmd) code_build_pgm                                   ; \
	else                                                                   \
		if [ $(product_type) = "lib" ]; then                           \
			$(make_cmd) code_build_lib                           ; \
		else                                                           \
			if [ $(product_type) = "just_copy" ]; then             \
				$(make_cmd) code_build_just_copy             ; \
			fi                                                   ; \
		fi                                                           ; \
	fi                                                                   ;

#@public@|code_build_chain|Builds the Code of the Project
#@public_detailed@|code_build_chain|Syntax: 'make project=<project-name> [coc=<cpu-os-compiler>] [verbose=0/1]  [target=debug/release] code_build_chain
#@public_detailed@|code_build_chain|Where <project-name> is an existing project. Please rum 'make prj_list' to list all the avaiable projects.
#@public_detailed@|code_build_chain|Where <cpu-os-compiler> is the name of a file that contain definitions for a CPU, OS and compiler. Please, run 'make coc_list' to list all the combinations avaiables.
#@public_detailed@|code_build_chain|If the Project builds a program, i.e. the variable 'product_type' in the 'tenacitas.build_system/cpp/bin/$(project)/tool/gmake/project.mk' file values '$(program)', the executable generated is placed in the directory referenced in the variable 'build_bin_dir', which is defined in the 'tenacitas.build_system/cpp/tool/gmake/cpu_os_comp/$(coc).mk' file. 
#@public_detailed@|code_build_chain|If the Project builds a libray, i.e. the variable 'product_type' in the 'tenacitas.build_system/cpp/bin/$(project)/tool/gmake/project.mk' file values '$(library)', the static and dymanic libraries generated are placed in the directory referenced in the variable 'build_lib_dir', which is defined in the 'tenacitas.build_system/cpp/tool/gmake/cpu_os_comp/$(coc).mk' file. 
#@public_detailed@|code_build_chain|If the variable 'product_type' in the 'tenacitas.build_system/cpp/bin/$(project)/tool/gmake/project.mk' file values '$(just_copy_files)', the existing files in the directory 'tenacitas.build_system/cpp/src/$(project)/code' are copied to the directory referenced in the variable 'build_inc_dir', which is defined in the 'tenacitas.build_system/cpp/tool/gmake/cpu_os_comp/$(coc).mk' file.
code_build_chain :
	$(show) ""                                                           ; \
	echo "**************************************** "                     ; \
	echo -n "Building the code of all Projects that $(project) "         ; \
	echo "depend on"                                                     ; \
	$(make_cmd) chain chain_target=code_build                            ; \
	$(make_cmd) code_build                                               ;


#@public@|code_clean|Cleans the Code of the Project
#@public_detailed@|code_clean|Syntax: 'make project=<project-name> [coc=<cpu-os-compiler>] [verbose=0/1]  [target=debug/release] code_clean
#@public_detailed@|code_clean|Where <project-name> is an existing project. Please rum 'make prj_list' to list all the avaiable projects.
#@public_detailed@|code_clean|Where <cpu-os-compiler> is the name of a file that contain definitions for a CPU, OS and compiler. Please, run 'make coc_list' to list all the combinations avaiables.
code_clean : 
	$(show) " "                                                          ; \
	echo "**************************************** "                     ; \
	echo "Cleaning the code of  $(project)"                              ; \
	rm -rf $(dir_src)/*~ 2> /dev/null                                    ; \
	rm -rf $(dir_inc)/*~ 2> /dev/null                                    ; \
	rm -rf $(dir_bin)/*$(project)* 2> /dev/null                          ; \
	rm -rf $(dir_lib)/*$(project)* 2> /dev/null                          ; \
	rm -rf $(dir_tst)/*~          2> /dev/null                          ; \
	rm -f  $(dir_prj)/.hs  2> /dev/null                                  ; \
	rm -f  $(dir_prj)/BROWSE 2> /dev/null                                ; \
	rm -f  $(dir_prj)/TAGS 2> /dev/null                                  ; \
	rm -f  $(dir_prj)/.*_current_headers*  2> /dev/null                  ; \
	rm -f  $(dir_prj)/.*_hs 2> /dev/null                                 ; \
	rm -f  $(dir_src)/.*deps 2> /dev/null                                ; \
	rm -f  $(dir_obj)/*.$(obj_extension) 2> /dev/null                    ; 

#setup

#@public@|code_clean_chain|Cleand the code of all the projects that this project depends on, and the project itself.
#@public_detailed@|code_clean_chain|Syntax: 'make project=<project-name> [coc=<cpu-os-compiler>] [verbose=0/1]  [target=debug/release] code_clean
#@public_detailed@|code_clean_chain|Where <project-name> is an existing project. Please rum 'make prj_list' to list all the avaiable projects.
#@public_detailed@|code_clean_chain|Where <cpu-os-compiler> is the name of a file that contain definitions for a CPU, OS and compiler. Please, run 'make coc_list' to list all the combinations avaiables.
code_clean_chain :
	$(show) ""                                                           ; \
	echo "**************************************** "                     ; \
	echo -n "Cleaning the code of all Projects that $(project) "         ; \
	echo "depend on"                                                     ; \
	$(make_cmd) chain chain_target=code_clean                            ; \
	$(make_cmd) code_clean                                               ;

